﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WEALTH.Manager.BaseSystem
{
    public partial class MenuInsert : BasePage
    {
        ExcuteDao ExcuteDao = new ExcuteDao();
        public string str_sess_code = "", str_sql = "", str_link = "", strMsg = "", mcode = "", DisplayOrder = "";
        public int n = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            str_sess_code = Request.QueryString["code"].ToString().Trim();
            mcode = ExcuteDao.Get_MenuCode(str_sess_code).Rows[0][0].ToString();
            if (!IsPostBack)
            {
                rblMenu_IsUse.SelectedValue = "1";

                if (string.IsNullOrEmpty(mcode))
                {
                    txtMenu_Code.Text = str_sess_code + "1";
                }
                else
                {
                    txtMenu_Code.Text = mcode;
                }
                txtDisplayOrder.Text = txtMenu_Code.Text;
            }
            btnInsert.CssClass = "submit";
        }
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            string MenuCode = txtMenu_Code.Text.Trim();
            string MenuName = txtMenu_Name.Text.Trim();
            string PMenuCode = str_sess_code.ToString().Trim();
            string FileName = txtMenu_FileName.Text.Trim();
            string Ico = txtIco.Text.Trim();
            string IsUse = rblMenu_IsUse.SelectedValue;

            if (string.IsNullOrEmpty(txtDisplayOrder.Text))
            {
                DisplayOrder = MenuCode;
            }
            else
            {
                DisplayOrder = txtDisplayOrder.Text.Trim();
            }

            n = ExcuteDao.AddMenu(MenuCode, MenuName, PMenuCode, FileName, Ico, DisplayOrder, IsUse);
            if (n > 0)
            {
                //Response.Write("<script>location.replace('MenuList.aspx?msg=添加菜单成功！');</script>");
                ReturnList("MenuList.aspx", "添加菜单成功！");
            }
            else
            {

                ShowMsg("添加菜单失败！", 1);
                return;
            }
            return;
        }
    }
}